package com.cloud.wxmana.ser;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.URIException;
import org.apache.http.client.ClientProtocolException;

import com.cloud.util.base.RetType;
import com.cloud.wxmana.entity.WxUserCache;
import com.cloud.wxmana.entity.WxmPublicAcc;
import com.cloud.wxmana.entity.WxtUser;

/**
 * 
 * @author humg
 * 2017年2月4日
 */
public interface IWxAhrService {
	

	/**
	 * 第一步：用户同意授权，获取code
	 * @param appId 微信公众号的APPID
	 * @param url	微信回调的URL
	 * @param state	重定向后会带上state参数，开发者可以填写a-zA-Z0-9的参数值，最多128字节 
	 * @throws URIException 
	 * @throws UnsupportedEncodingException 
	 * @throws IOException 
	 */	
	public String getCode(HttpServletResponse response,HttpServletRequest request) throws URIException, UnsupportedEncodingException, IOException;
	
	
	/**
	 * 通过code换取网页授权access_token
	 * @param appId	微信公众号的APPID
	 * @param secret 公众号的appsecret
	 * @param code 填写第一步获取的code参数
	 * @return
	 * @throws IOException 
	 */
	public String getAccess_Token(String code,HttpServletRequest request); 
	
	/**
	 * 第三步：刷新access_token（如果需要）
	 * @param appId
	 * @param refresh_token
	 * @return
	 * @throws IOException 
	 */
	public String UpdateAccess_Token(HttpServletResponse response,String appId,String refresh_token) throws IOException;
	
	
	/**
	 * 第四步：拉取用户信息(需scope为 snsapi_userinfo)
	 * @param access_token
	 * @param openid
	 * @return
	 * @throws IOException 
	 */
	public WxtUser getUserInfo(String access_token,String openid,String publicUuid,HttpServletRequest request ) throws IOException;

	
	/**
	 * 附：检验授权凭证（access_token）是否有效
	 * @param access_token
	 * @param openid
	 * @return
	 * @throws IOException 
	 */
	public String checkAccess_Token(HttpServletResponse response,String access_token,String openid) throws IOException; 

	
	/**
	 * 
	 * @param url
	 * @return GET向服务器发送请求
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	 public String doget(String url) throws ClientProtocolException, IOException;  
	 
		/**
		 * 根据openid，uuid获取微信用户
		 * @param openid
		 * @param uuid
		 * @return
		 */
	 public WxtUser getUserByOpenidAndUuid(String openid, String uuid);


		/**
		 * 根据用户id获取缓存信息
		 * @param code
		 * @return
		 */
	 public WxUserCache getUserCacheByid(String code);


		/**
		 * 根据用户id获取用户信息
		 * @param wxuid
		 * @return
		 */
	 public WxtUser getUserByid(String wxuid);


		/**
		 * 根据微信Uid获取用户缓存信息
		 * @param wxuid
		 * @return
		 */
	 public WxUserCache getUserCacheByUid(String wxuid);


		/**
		 * 根据微信公告UID获取公众号信息
		 * @param wxPublicUuid
		 * @return
		 */
	 public WxmPublicAcc getPublicAccByWxPubUid(String wxPublicUuid);


		/**
		 * 删除缓存信息
		 * @param userCache
		 */
	 public void delUserCache(WxUserCache userCache);





	
	
}
